﻿using System.Collections.Generic;
using Landpy.LogAnalyzer.Configuration;

namespace Landpy.LogAnalyzer.Log
{
    public static class LogRowExtend
    {
        public static bool ContainsLogRow(this List<LogRow> logRows, LogRow logRow)
        {
            bool isContain = false;
            int similarLength = 10;
            foreach (LogRow tmpLogRow in logRows)
            {
                string exceptionColumnName = ConfigurationSession.GetSession().Setting.Columns[
                    ConfigurationSession.GetSession().Setting.Columns.Count - 1].HeaderText;
                string methodColumnName = ConfigurationSession.GetSession().Setting.Columns[
                    ConfigurationSession.GetSession().Setting.Columns.Count - 2].HeaderText;
                string typeColumnName = ConfigurationSession.GetSession().Setting.Columns[
                    ConfigurationSession.GetSession().Setting.Columns.Count - 3].HeaderText;
                isContain = (tmpLogRow[exceptionColumnName].Substring(0, similarLength) ==
                             logRow[exceptionColumnName].Substring(0, similarLength));
                isContain = isContain & (tmpLogRow[methodColumnName] == logRow[methodColumnName]);
                isContain = isContain & (tmpLogRow[typeColumnName] == logRow[typeColumnName]);
            }
            return isContain;
        }
    }
}